package com.qianzhou.eduCommon.vo;

import com.qianzhou.eduCommon.constant.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 描述：定义接口返回
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVO<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer status;
    private String msg;
    private T data;
    private static final Integer SUCCESS_STATUS = Constants.SUCCESS_STATUS;
    private static final Integer FAILURE_STATUS = Constants.FAILURE_STATUS;
    /*成功*/
    private static final String SUCCESS = Constants.SUCCESS;
    /*失败*/
    private static final String FAILURE = Constants.FAILURE;

    /*响应成功返回api接口*/
    public static <T> ResultVO<T> ok() {
        return new ResultVO<T>(SUCCESS_STATUS, SUCCESS, null);
    }

    public static <T> ResultVO<T> ok(T data) {
        return new ResultVO<T>(SUCCESS_STATUS, SUCCESS, data);
    }

    public static <T> ResultVO<T> ok(Integer status, String msg) {
        return new ResultVO<T>(status, msg, null);
    }

    public static <T> ResultVO<T> ok(Integer status, String msg, T data) {
        return new ResultVO<>(status, msg, data);
    }

    public static <T> ResultVO<T> fail() {
        return new ResultVO<T>(FAILURE_STATUS, FAILURE, null);
    }

    public static <T> ResultVO<T> fail(T data) {
        return new ResultVO<T>(FAILURE_STATUS, FAILURE, data);
    }

    public static <T> ResultVO<T> fail(Integer status, String msg) {
        return new ResultVO<T>(status, msg, null);
    }

    public static <T> ResultVO<T> fail(Integer status, String msg, T data) {
        return new ResultVO<T>(status, msg, data);
    }
}
